package base.ioput.StremIO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * InputStream 属于字节流 范围了
 */
public class FileStreamDemo {

    public static void main(String[] args) throws IOException {
        readFile_3();
    }


    public static void writeOutputStream() throws IOException {
        FileOutputStream fos = new FileOutputStream("fos.txt");//创建文件
        fos.write("abcde".getBytes());//输入类型write(byte[] b)  write(int b)
        //输入时要么一个字节要么一个数组，不然就转换
        fos.close();
    }

    public static void readInputStream_1() throws IOException {
        FileInputStream fis = new FileInputStream("fos.txt");//只读取文件
        int ch = 0;
        while ((ch = fis.read()) != -1) {
            System.out.println((char) ch);
        }
        fis.close();
    }

    public static void readFile_2() throws IOException {
        FileInputStream fis = new FileInputStream("fos.txt");
        byte[] buf = new byte[1024];
        int len = 0;
        while ((len = fis.read(buf)) != -1) {
            System.out.println(new String(buf, 0, len));
        }
        fis.close();
    }

    public static void readFile_3() throws IOException {
        FileInputStream fis = new FileInputStream("fos.txt");

//		int num = fis.available();
        byte[] buf = new byte[fis.available()];//定义一个刚刚好的缓冲区。不用在循环了。

        fis.read(buf);

        System.out.println(new String(buf));

        fis.close();
    }





}
